package de.haw.HES.base;

import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

import de.haw.HES.Datentypen.AuftragTyp;
import de.haw.HES.Datentypen.KundenTyp;
import de.haw.HES.base.DispositionAdapterService;

public class ServiceServer extends UnicastRemoteObject implements DispositionAdapterService {

	protected ServiceServer() throws RemoteException {
		super();
		// TODO Auto-generated constructor stub
	}

	@Override
	public boolean hasBeenDelivered(Integer id) throws RemoteException {
		DispositionAdapterService das = (DispositionAdapterService) ApplicationContextProvider
				.getApplicationContext().getBean(
						"de.haw.HES.Disposition.pub.DispositionAdapterService");
		return das.hasBeenDelivered(id);
	}

	@Override
	public void createDeliveryForOrder(AuftragTyp auftrag, KundenTyp kunde) throws RemoteException {
		DispositionAdapterService das = (DispositionAdapterService) ApplicationContextProvider
				.getApplicationContext().getBean(
						"de.haw.HES.Disposition.pub.DispositionAdapterService");
		createDeliveryForOrder(auftrag, kunde);
	}
	
	public static void main(String[] args) {

		try {
			
			Registry registry = LocateRegistry.getRegistry();
			registry.bind("blubdererste", new ServiceServer());
			System.out.println("System running and ready for requests");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			System.err.println("Server start failed");
			e.printStackTrace();
		} 
		
	}

}
